﻿using ZFY.Blog.Api.Model;
using Microsoft.AspNetCore.Http;
using System;
using System.IO;
using System.Linq;

namespace ZFY.Blog.Api.Common
{
    public class ReuseMethod
    {
        public static void ImageFormatCheck(string imageNmae)
        {
            var imageFormat = new string[] { "jpg","gif","ico","png" };
            var fileFormat = imageNmae.Substring(imageNmae.LastIndexOf(".") + 1);
            if (!imageFormat.Contains(fileFormat))
            {
                throw new UIException("图片格式错误");
            }
        }
        public static async System.Threading.Tasks.Task<byte[]> GetFileBufferAsync(IFormFile file)
        {
            var buffer = new byte[file.Length];
            var stream = file.OpenReadStream();
            await stream.ReadAsync(buffer, 0, (int)file.Length);
            return buffer;
        }
    }
}
